﻿using B.S.BasicData.Api.Write.Application.Command.User;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Write.Controllers
{
    /// <summary>
    /// 角色服务
    /// </summary>
    [Route("api/[controller][action]")]
    [ApiController]
    [Authorize]
    public class RoleController : ControllerBase
    {
        IMediator _mediator;

        public RoleController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 添加角色信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<ApiResult<int>> CreateRole(CreateRoleCommand request)
        {
            return _mediator.Send(request);
        }
        /// <summary>
        /// 删除角色信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpDelete]
        public Task<ApiResult<int>> DeleteRole([FromQuery]DeleteRoleCommand request)
        {
            return _mediator.Send(request);
        }
        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<ApiResult<int>> UpdateRole(UpdateRoleCommand request)
        {
            return _mediator.Send(request);
        }

        /// <summary>
        /// 用户角色保存
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<ApiResult<int>> SaveUserRole(AddUserRoelCommand request)
        {
            return _mediator.Send(request);
        }
        
    }
}
